﻿<UserControl 
    x:Class="myManga.Views.SearchView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:manager="clr-namespace:Manga.Manager;assembly=Manga"
    Background="Black" Foreground="White" TextElement.Foreground="White">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" MinHeight="21"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <ListBox 
            Grid.Row="1" Grid.Column="1"
            ItemsSource="{Binding Path=SearchCollection, IsAsync=True}"
            SelectedItem="{Binding Path=SearchInf, IsAsync=True}"
            Background="Transparent"
            Foreground="White"
            BorderThickness="0"
            AlternationCount="2">
            <ListBox.Resources>
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter 
                        Property="Template">
                        <Setter.Value>
                            <ControlTemplate 
                                TargetType="{x:Type ListBoxItem}">
                                <Grid x:Name="ItemContainer" Cursor="Hand" Background="#0000">
                                    <Grid.RowDefinitions>
                                        <RowDefinition/>
                                        <RowDefinition/>
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="39"/>
                                        <ColumnDefinition/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <Border
                                        BorderThickness="1"
                                        BorderBrush="White"
                                        HorizontalAlignment="Center"
                                        VerticalAlignment="Center"
                                        Margin="5"
                                        Grid.RowSpan="2">
                                        <Image 
                                            MaxHeight="37"
                                            MaxWidth="37"
                                            Source="{Binding Path=CoverLocation, FallbackValue=/myManga;component/Resources/Images/Icons/FalbackMangaIcon.png}"/>
                                    </Border>
                                    <TextBlock 
                                        Grid.Column="1"
                                        Padding="5,0,0,0"
                                        VerticalAlignment="Center"
                                        Text="{Binding Path=Title}"
                                        TextTrimming="CharacterEllipsis"
                                        FontSize="16"/>
                                    <TextBlock 
                                        Grid.Column="1"
                                        Grid.Row="1"
                                        Padding="15,0,0,0"
                                        VerticalAlignment="Center"
                                        Text="{Binding Path=Artist}"/>
                                    <Button
                                        Grid.Column="2"
                                        Grid.RowSpan="2"
                                        Command="{Binding Path=DataContext.DownloadMangaInfo, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}"
                                        CommandParameter="{Binding}" 
                                        Style="{StaticResource GlowBtn}">
                                        <Image Source="/myManga;component/Resources/Images/Metro/White/No%20Circle/Cloud-download.png" />
                                    </Button>
                                </Grid>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                                        <Setter TargetName="ItemContainer" Property="Background" Value="#111"/>
                                    </Trigger>
                                    <Trigger Property="IsSelected" Value="True">
                                        <Setter TargetName="ItemContainer" Property="Background" Value="#555"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ListBox.Resources>
        </ListBox>
        <Expander 
            Grid.Row="1" 
            Background="#252525"
            Foreground="White" 
            FontSize="17" 
            x:Name="DetailsExpander" 
            IsEnabled="{Binding DetailsEnabled}" 
            IsExpanded="{Binding DetailsOpen}" 
            ExpandDirection="Right">
            <Expander.Header>
                <TextBlock Margin="1,5"  Text="{Binding Path=SearchInf.Title, StringFormat=Details - {0}, FallbackValue=Details - Unknown}">
                    <TextBlock.LayoutTransform>
                        <RotateTransform Angle="270"/>
                    </TextBlock.LayoutTransform>
                </TextBlock>
            </Expander.Header>
            <Grid DataContext="{Binding Path=DetailsInfo, IsAsync=True}" TextElement.FontSize="12" Width="336">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <StackPanel>
                    <TextBlock Margin="3,1" TextWrapping="Wrap">
                        <Bold Foreground="LightGray">Alt. Title:</Bold> <Run Text="{Binding Path=AltTitle, FallbackValue=Unknown, Mode=OneWay}"/>
                    </TextBlock>
                    <TextBlock Margin="3,1" TextWrapping="Wrap">
                        <Bold Foreground="LightGray">Released:</Bold> <Run Text="{Binding Path=Released, FallbackValue=Unknown, Mode=OneWay}"/>
                    </TextBlock>
                    <TextBlock Margin="3,1" TextWrapping="Wrap">
                        <Bold Foreground="LightGray">Status:</Bold> <Run Text="{Binding Path=Status, FallbackValue=Unknown, Mode=OneWay}"/>
                    </TextBlock>
                    <TextBlock Margin="3,1" TextWrapping="Wrap">
                        <Bold Foreground="LightGray">Author:</Bold> <Run Text="{Binding Path=Author, FallbackValue=Unknown, Mode=OneWay}"/>
                    </TextBlock>
                    <TextBlock Margin="3,1" TextWrapping="Wrap">
                        <Bold Foreground="LightGray">Artist:</Bold> <Run Text="{Binding Path=Artist, FallbackValue=Unknown, Mode=OneWay}"/>
                    </TextBlock>
                    <TextBlock Margin="3,1" TextWrapping="Wrap">
                        <Bold Foreground="LightGray">Genre:</Bold> <Run Text="{Binding Path=Genre, FallbackValue=Unknown, Mode=OneWay}"/>
                    </TextBlock>
                </StackPanel>
                <ListBox
                        x:Name="ChapterList"
                        Background="#111"
                        Grid.Row="1"
                        ItemsSource="{Binding Path=ChapterEntries, IsAsync=True}" 
                        HorizontalContentAlignment="Stretch"
                        BorderThickness="0"
                        AlternationCount="2"
                        ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                    <ListBox.Resources>
                        <Style TargetType="{x:Type ListBoxItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                        <Border x:Name="_Item" BorderThickness="1" Padding="2" Background="#0000">
                                            <Grid TextBlock.Foreground="White">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition/>
                                                    <ColumnDefinition Width="Auto"/>
                                                </Grid.ColumnDefinitions>
                                                <StackPanel>
                                                    <TextBlock TextWrapping="NoWrap" TextTrimming="CharacterEllipsis">
                                                            <TextBlock.Text>
                                                                <MultiBinding StringFormat="{}v{0} c{1}.{2}">
                                                                    <Binding Path="Volume"/>
                                                                    <Binding Path="Chapter"/>
                                                                    <Binding Path="SubChapter"/>
                                                                </MultiBinding>
                                                            </TextBlock.Text>
                                                    </TextBlock>
                                                    <TextBlock x:Name="TitleName" Padding="10,0,0,0" FontSize="16" Text="{Binding Path=Name, FallbackValue=Un-Named}" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis"/>
                                                </StackPanel>
                                            </Grid>
                                        </Border>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                                                <Setter TargetName="_Item" Property="Background" Value="#333"/>
                                            </Trigger>

                                            <Trigger Property="IsSelected" Value="True">
                                                <Setter TargetName="_Item" Property="Background" Value="#555"/>
                                            </Trigger>
                                            <Trigger Property="IsMouseOver" Value="True">
                                                <Setter TargetName="_Item" Property="Background" Value="#999"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ListBox.Resources>
                </ListBox>
                <ToggleButton Grid.RowSpan="2" IsChecked="{Binding ElementName=DetailsExpander, Path=IsExpanded, Mode=TwoWay, IsAsync=True}" Width="17" Grid.Column="1">
                    <ToggleButton.Background>
                        <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                            <GradientStop Color="#111" Offset="1" />
                            <GradientStop Color="#252525" Offset="0.5" />
                        </LinearGradientBrush>
                    </ToggleButton.Background>
                </ToggleButton>
            </Grid>
        </Expander>
        <Border BorderBrush="White" BorderThickness="0,0,0,1" Grid.ColumnSpan="2">
            <Grid Margin="0,0,0,8">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition/>
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <ComboBox
                    Margin="3,1,0,1"
                    ItemsSource="{Binding Source={x:Static manager:Global_IMangaPluginCollection.Instance}, Path=Plugins}"
                    SelectedItem="{Binding Path=Plugin}"
                    DisplayMemberPath="SiteName"/>
                <TextBox 
                    x:Name="SearchText"
                    Grid.Column="1"
                    Background="#00000000"
                    Foreground="White"
                    FontSize="16"
                    BorderThickness="0"
                    VerticalAlignment="Center">
                    <TextBox.InputBindings>
                        <KeyBinding 
                            Key="Enter" 
                            Command="{Binding Path=SearchMangaText}"
                            CommandParameter="{Binding ElementName=SearchText, Path=Text}"/>
                    </TextBox.InputBindings>
                </TextBox>
                <Button 
                    Grid.Column="2" 
                    Margin="2" 
                    Command="{Binding Path=SearchMangaText}"
                    CommandParameter="{Binding ElementName=SearchText, Path=Text}">
                    <StackPanel Orientation="Horizontal">
                        <Image Width="21" Margin="-3"
                            Source="/myManga;component/Resources/Images/Metro/Black/No%20Circle/Find.png"/>
                        <TextBlock Padding="2,0,0,0" Text="{DynamicResource ResourceKey=SearchButtonText}" VerticalAlignment="Center" Foreground="Black"/>
                    </StackPanel>
                </Button>
                <ProgressBar
                    x:Name="loadProgress"
                    Grid.ColumnSpan="3"
                    Grid.ZIndex="99"
                    Value="{Binding Path=Progress, Mode=OneWay, FallbackValue=50}"
                    VerticalAlignment="Bottom"
                    IsHitTestVisible="False"
                    Visibility="{Binding Path=ProgressVisibility}"
                    Margin="0,0,0,-17"/>
            </Grid>
        </Border>
    </Grid>
</UserControl>
